import { SendDepts } from './sendDept';
let _SendDepts = SendDepts;
/**
 * 拷贝下面两行到 mock/index.js中,即可支持客户端虚拟数据、免服务端连接
 * import SendDeptMock from './mdp/arc/send/sendDeptMock';
 * SendDeptMock.bootstrap(mock);
 */
export default {
  /**
   * mock bootstrap
   */
  bootstrap(mock) {    
  
    //获取列表 模糊查询、根据关键字查询
    mock.onGet('/mdp/arc/send/sendDept/listKey').reply(config => {
      let params = config.params;
      let mockSendDepts = _SendDepts.filter(sendDept => {
      	if(params.id||params.id==''){ if( sendDept.id.indexOf(params.id)>=0) return true;}
      	if(params.deptid||params.deptid==''){ if( sendDept.deptid.indexOf(params.deptid)>=0) return true;}
      	if(params.remark||params.remark==''){ if( sendDept.remark.indexOf(params.remark)>=0) return true;}
      	if(params.createDate||params.createDate==''){ if( sendDept.createDate.indexOf(params.createDate)>=0) return true;}
      	if(params.sendFinishDate||params.sendFinishDate==''){ if( sendDept.sendFinishDate.indexOf(params.sendFinishDate)>=0) return true;}
      	if(params.isSendSuccess||params.isSendSuccess==''){ if( sendDept.isSendSuccess.indexOf(params.isSendSuccess)>=0) return true;}
      	if(params.sendPlanId||params.sendPlanId==''){ if( sendDept.sendPlanId.indexOf(params.sendPlanId)>=0) return true;}
        return false;
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            data: mockSendDepts
          }]);
        }, 1000);
      });
    });
    
    

    //获取列表（分页/不分页）
    mock.onGet('/mdp/arc/send/sendDept/list').reply(config => {
      let params = config.params;
      let mockSendDepts = _SendDepts.filter(sendDept => {
      	var isTrue=false;
      	if(params.id||params.id==''){if(sendDept.id.indexOf(params.id)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.deptid||params.deptid==''){if(sendDept.deptid.indexOf(params.deptid)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.remark||params.remark==''){if(sendDept.remark.indexOf(params.remark)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.createDate||params.createDate==''){if(sendDept.createDate.indexOf(params.createDate)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.sendFinishDate||params.sendFinishDate==''){if(sendDept.sendFinishDate.indexOf(params.sendFinishDate)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.isSendSuccess||params.isSendSuccess==''){if(sendDept.isSendSuccess.indexOf(params.isSendSuccess)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.sendPlanId||params.sendPlanId==''){if(sendDept.sendPlanId.indexOf(params.sendPlanId)>=0){isTrue=true;}else{isTrue=false;}}
      	return isTrue;
	  });
      if(!config.params.currentPage){ 
	      return new Promise((resolve, reject) => {
	        setTimeout(() => {
	          resolve([200, {
	            data: mockSendDepts
	          }]);
	        }, 1000);
	      });
      }
    
      let {pageSize,currentPage, total} = config.params;
      total = mockSendDepts.length;
      mockSendDepts = mockSendDepts.filter((sendDept, index) => index < pageSize * currentPage && index >= pageSize * (currentPage - 1));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            pageInfo: {
            	total:total
            },
            data: mockSendDepts,
            tips:{
            	isOk:true,
            	msg:'查询成功'
            }
          }]);
        }, 1000);
      });
    });

    //删除
    mock.onPost('/mdp/arc/send/sendDept/del').reply(config => {
      var params = JSON.parse( config.data );
      let {  id  } = params;
      _SendDepts = _SendDepts.filter(sendDept => sendDept.id !== id);
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //批量删除
    mock.onPost('/mdp/arc/send/sendDept/batchDel').reply(config => {
      var params = JSON.parse( config.data );
      _SendDepts = _SendDepts.filter(sendDept => !params.includes(sendDept.id));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
           tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //编辑
    mock.onPost('/mdp/arc/send/sendDept/edit').reply(config => {
      var params = JSON.parse( config.data );
      let { id,deptid,remark,createDate,sendFinishDate,isSendSuccess,sendPlanId } = params;
      _SendDepts.some(sendDept => {
        if (sendDept.id === id) {
			sendDept.id = id;
			sendDept.deptid = deptid;
			sendDept.remark = remark;
			sendDept.createDate = createDate;
			sendDept.sendFinishDate = sendFinishDate;
			sendDept.isSendSuccess = isSendSuccess;
			sendDept.sendPlanId = sendPlanId
          return true;
        }
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'编辑成功'
            }
          }]);
        }, 500);
      });
    });

    //新增
    mock.onPost('/mdp/arc/send/sendDept/add').reply(config => {
      var params = JSON.parse( config.data );
      let { id,deptid,remark,createDate,sendFinishDate,isSendSuccess,sendPlanId } = params;
      _SendDepts.push({
		id:id,
		deptid:deptid,
		remark:remark,
		createDate:createDate,
		sendFinishDate:sendFinishDate,
		isSendSuccess:isSendSuccess,
		sendPlanId:sendPlanId
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'新增成功'
            }
          }]);
        }, 500);
      });
    });

  }
};